package com.eight.homepage.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.eight.common.pojo.TbLink;
import com.eight.common.vo.Result;

import com.eight.homepage.service.LinkService;
import com.eight.homepage.vo.LinkVo;
import com.eight.homepage.vo.LinkVo3;
import com.eight.homepage.vo.LinkVo4;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @program: educaion-parent
 * @description:
 * @author: 平家祥
 * @create: 2023-05-27 15:00
 **/
@RestController
@RequestMapping("/home/link")
@Api(tags = "友情链接")
public class LinkController {
    @Autowired
    private LinkService linkService;
    @PostMapping("/getAllLink/{current}/{pageSize}")
    @ApiOperation("所有连接")
    public Result getAllLink(@PathVariable Integer current,
                             @PathVariable Integer pageSize,
                             @RequestBody LinkVo linkVo){
        Page<TbLink> allLink = linkService.getAllLink(current, pageSize, linkVo);
        return Result.success(allLink);
    }
    @ApiOperation("修改状态")
    @PostMapping("/changeStatus/{linkId}/{isDisable}")
    public Result changeStatus(@PathVariable String linkId,
                               @PathVariable Integer isDisable){
        Integer i = linkService.updateById(linkId,isDisable);
        if(i > 0 ){
            return Result.success();
        }else {
            return Result.fail();
        }
    }

    @ApiOperation("修改")
    @PostMapping("/editLink")
    public Result editLink(@RequestBody LinkVo3 linkVo3){
        Integer i = linkService.updateById1(linkVo3);
        if (i > 0 ){
            return Result.success();
        }else{
            return Result.fail();
        }
    }

    @ApiOperation("添加")
    @PostMapping("/addLink")
    public Result addLink(@RequestBody LinkVo4 linkVo4){
        Integer i = linkService.insert(linkVo4);
        if (i > 0 ){
            return Result.success();
        }else{
            return Result.fail();
        }
    }

    @ApiOperation("删除")
    @PostMapping("/deleteLink/{linkId}")
    public Result deleteLink(@PathVariable String linkId){
        Integer i = linkService.deleteById(linkId);
        if (i > 0 ){
            return Result.success();
        }else{
            return Result.fail();
        }
    }

}
